package com.ws.haungjia.controller;

import com.ws.haungjia.Bean.HoutaiUser;
import com.ws.haungjia.Bean.User;
import com.ws.haungjia.Service.DengluService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class Houtai {
    @Autowired
    private DengluService dengluService;
    @RequestMapping("Hdenglu")
    public String denglu(String hname, String pass , HttpServletRequest request) throws Exception{
        String s = DigestUtils.md5DigestAsHex(pass.getBytes());
        HoutaiUser hdenglu = dengluService.Hdenglu(hname, s);
        if (hdenglu != null) {
            request.getSession().setAttribute("huser", hdenglu);
            return "WEB-INF/houtai/index";
        }else{
            return "login";
        }
    }

    @RequestMapping("/htuichu")
    public String tuichu(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return "login";
    }
}
